package com.example.helloword.servie;

import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.AsyncResult;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.concurrent.Future;

@Service
@Slf4j
public class ServiceHandle {
//    @Async(value = "doSomethingExecutor")
    @Async
    public Future<String> handle1() throws InterruptedException {
        String name = Thread.currentThread().getName();
        log.info("{} beg", name);
        //异步处理
        Thread.sleep(5000);
        log.info("{} end", name);

        return new AsyncResult<>(name + "Ok");
    }

//    @Async(value = "otherSomethingExecutor")
    @Async
    public Future<String> handle2() throws InterruptedException {
        String name = Thread.currentThread().getName();
        log.info("{} beg", name);
        //异步处理
        Thread.sleep(5000);
        log.info("{} end", name);

        return new AsyncResult<>(name + "Ok");
    }

    @Async
    public Future<String> handle3() throws InterruptedException {
        String name = Thread.currentThread().getName();
        log.info("{} beg", name);
        //异步处理
        Thread.sleep(5000);
        log.info("{} end", name);

        return new AsyncResult<>(name + "Ok");
    }

    @Transactional
    public void handle4() {
        System.out.println("111");
        return;
    }
}
